<?php
class LoginController extends  AppController {
	var $name = 'Login';
	var $helpers = array('Html');
	var $uses = array('User');
	
	function index(){
			$this->layout = 'login';
			$username = mysql_escape_string($this->data['Login']['username']);
			$password = md5(mysql_escape_string($this->data['Login']['password']));
			
			if (!empty($username)) {
				$row = $this->User->login($username, $password);
				if (!empty($row)) {
					$this->Session->write('admin', $row['User']);
					$login = true;
					$this->redirect('/');
				}
				else {
					$this->Session->setFlash(__('Login Unsuccesfully', true));
				}
			}
		}
		
		function logout(){
			$this->Session->delete('admin');
			$this->redirect('/login');
		}
}